package com.everyday.practice.algorithm;

/**
 * @description:
 * @author: leon
 * @time: 2021/6/16 17:09
 */
public class Title53 {
    public int maxSubArray(int[] nums) {
        int old=nums[0];
        int index=nums[0];
        for (int i=1;i<nums.length;i++){
            if (index<0){
                if (nums[i]>index){
                    index=nums[i];
                }
            }else if (index>=0){
                index=index+nums[i];
            }
            old=Math.max(old,index);
        }
        return old;
    }
}
